<script language="javascript">
    $(function() {
        $("#hascommission").click(function() {
            var obj = $(this);
            if (obj.get(0).checked) {
                $("#commission_div").show();
            } else {
                $("#commission_div").hide();
            }
        });
    })
</script>

<div class="region-goods-details row">
    <div class="region-goods-left col-sm-2">分销</div>
    <!--chemeng-->
    <div class="region-goods-right col-sm-10">
        <div class="form-group">
            <label class="col-sm-2 control-label">级差奖状态</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="1" name="unlimited_status" {if $item['unlimited_status'] == 1}checked{/if} /> 开启
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="0" name="unlimited_status" {if empty($item['unlimited_status'])}checked{/if} /> 不开启
                </label>
                <span class="help-block">如果不开启，则不产生级差奖</span>
                {else}
                <div class='form-control-static'>{if $item['unlimited_status']==1}参与{else}不参与{/if}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">级差奖规则</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="1" name="unlimited_type" {if $item['unlimited_type'] == 1}checked{/if} /> 独立规则
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="0" name="unlimited_type" {if empty($item['unlimited_type'])}checked{/if} />  分销等级规则
                </label>
                {else}
                <div class='form-control-static'>{if $item['unlimited_type']==1}独立规则{else}分销等级规则{/if}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">固定金额/百分比</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="1" name="choseprice" {if $item['choseprice'] == 1}checked{/if} /> 固定金额
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="0" name="choseprice" {if empty($item['choseprice'])}checked{/if} />  百分比
                </label>
                {else}
                <div class='form-control-static'>{if $item['choseprice']==1}独立规则{else}分销等级规则{/if}</div>
                {/if}
            </div>
        </div>
        {if !empty($commission_level_cvmax)}
            {loop $commission_level_cvmax $ll}
                <div class="form-group">
                    <label class="col-sm-2 control-label">级差奖-{$ll['levelname']}</label>
                    <div class="col-sm-4 col-xs-12">
                        {ife 'goods' $item}
                        <div class="input-group">
                            <input type="text" name="unlimited_commission[{$ll['id']}]" id="unlimited_commission[{$ll['id']]" class="form-control" value="{$item['unlimited_commission'][$ll['id']]}" />
                            <div class="input-group-addon">元</div>
                            <input type="text" name="percentage[{$ll['id']}]" id="percentage[{$ll['id']]" class="form-control" value="{$item['percentage'][$ll['id']]}" />
                            <div class="input-group-addon">%</div>
                        </div>
                        {else}
                        <div class='form-control-static'>固定: {$item['unlimited_commission'][$ll['id']]} 元</div>
                        {/if}
                    </div>
                </div>
            {/loop}
        {/if}
      	<!-- code by 渔河岸小店 -->
      	<div class="form-group">
            <label class="col-sm-2 control-label">是否使用人人分销</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="0" name="everyone_distribution" {if $item['everyone_distribution']==0}checked{/if} /> 使用人人分销
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="1" name="everyone_distribution" {if $item['everyone_distribution']==1}checked{/if} /> 使用固定金额分销
                </label>
                {else}
                <div class='form-control-static'>{if $item['everyone_distribution']==1}使用固定金额分销{else}使用人人分销{/if}</div>
                {/if}
            </div>
        </div>
      
        <div class="form-group">
            <label class="col-sm-2 control-label">是否参与分销</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="0" name="nocommission" {if $item['nocommission']==0}checked{/if} /> 参与分销
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="1" name="nocommission" {if $item['nocommission']==1}checked{/if} /> 不参与分销
                </label>
                <span class="help-block">如果不参与分销，则不产生分销佣金</span>
                {else}
                <div class='form-control-static'>{if $item['nocommission']==1}不参与分销{else}参与分销{/if}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">分享按钮</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="radio-inline">
                    <input type="radio"  value="0" name="sharebtn" {if empty($item['sharebtn'])}checked{/if} /> 弹出关注提示层
                </label>
                <label class="radio-inline">
                    <input type="radio"  value="1" name="sharebtn" {if !empty($item['sharebtn'])}checked{/if} /> 跳转至商品海报
                </label>
                {else}
                <div class='form-control-static'>{if $item['nocommission']==1}不参与分销{else}参与分销{/if}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">海报图片</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                {php echo tpl_form_field_image2('commission_thumb', $item['commission_thumb'])}
                <span class='help-block'>尺寸: 640*640，如果为空默认缩略图片</span>
                {else}
                {if !empty($item['commission_thumb'])}
                <a href='{php echo tomedia($item['commission_thumb'])}' target='_blank'>
                <img src="{php echo tomedia($item['commission_thumb'])}" style='width:100px;border:1px solid #ccc;padding:1px' />
                </a>
                {/if}
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">独立规则</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <label class="checkbox-inline">
                    <input type="checkbox" id="hascommission" value="1" name="hascommission" {if $item['hascommission']==1}checked{/if} />启用独立佣金比例
                </label>
                <span class="help-block">启用独立佣金设置，此商品拥有独自的佣金比例,不受分销商等级比例及默认设置限制</span>
                {else}
                <div class='form-control-static'>{if $item['hascommission']==1}启用独立佣金设置{else}不启用独立佣金设置{/if}</div>
                {/if}
            </div>
        </div>

        <div id="commission_div" {if empty($item['hascommission'])}style="display:none"{/if} >


        <div class="form-group">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-10">
                {ife 'goods' $item}
                <label for="commission_type0" class="radio-inline"><input type="radio" name="commission_type" value="0" id="commission_type0" {if empty($commission_type) || $commission_type == 0}checked="true"{/if} /> 统一分销佣金</label>
                <label for="commission_type1" class="radio-inline"><input type="radio" name="commission_type" value="1" id="commission_type1"  {if !empty($commission_type) && $commission_type == 1}checked="true"{/if} /> 详细设置分销佣金</label>
                {else}
                <div class='form-control-static'>
                    {if empty($commission_type) || $commission_type == 0}统一设置折扣{/if}
                    {if !empty($commission_type) && $commission_type == 1}详细设置折扣{/if}
                </div>

                {/if}
            </div>
        </div>

        <div id="commission_0"  {if $commission_type!=0} style="display:none;" {/if}>
        <div class='alert alert-danger'>
            如果比例为空，则使用固定规则，如果都为空则无分销佣金
        </div>
        {if $com_set['level']>=1}
        <div class="form-group">
            <label class="col-sm-2 control-label">一级分销</label>
            <div class="col-sm-4 col-xs-12">
                {ife 'goods' $item}
                <div class="input-group">
                    <input type="text" name="commission1_rate" id="commission1_rate" class="form-control" value="{$item['commission1_rate']}" />
                    <div class="input-group-addon">% 固定</div>
                    <input type="text" name="commission1_pay" id="commission1_pay" class="form-control" value="{$item['commission1_pay']}" />
                    <div class="input-group-addon">元</div>
                </div>
                {else}
                <div class='form-control-static'>比例: {$item['commission1_rate']}% 固定: {$item['commission1_pay']} 元</div>
                {/if}
            </div>
        </div>
        {/if}
        {if $com_set['level']>=2}
        <div class="form-group">
            <label class="col-sm-2 control-label">二级分销</label>
            <div class="col-sm-4 col-xs-12">
                {ife 'goods' $item}
                <div class="input-group">
                    <input type="text" name="commission2_rate" id="commission2_rate" class="form-control" value="{$item['commission2_rate']}" />
                    <div class="input-group-addon">% 固定</div>
                    <input type="text" name="commission2_pay" id="commission2_pay" class="form-control" value="{$item['commission2_pay']}" />
                    <div class="input-group-addon">元</div>
                </div>
                {else}
                <div class='form-control-static'>比例: {$item['commission2_rate']}% 固定: {$item['commission2_pay']} 元</div>
                {/if}
            </div>
        </div>
        {/if}
        {if $com_set['level']>=3}
        <div class="form-group">
            <label class="col-sm-2 control-label">三级分销</label>
            <div class="col-sm-4 col-xs-12">
                {ife 'goods' $item}
                <div class="input-group">
                    <input type="text" name="commission3_rate" id="commission3_rate" class="form-control" value="{$item['commission3_rate']}" />
                    <div class="input-group-addon">% 固定</div>
                    <input type="text" name="commission3_pay" id="commission3_pay" class="form-control" value="{$item['commission3_pay']}" />
                    <div class="input-group-addon">元</div>
                </div>
                {else}
                <div class='form-control-static'>比例: {$item['commission3_rate']}% 固定: {$item['commission3_pay']} 元</div>
                {/if}
            </div>
        </div>
        {/if}
    </div>
    <div id="commission_1" {if $commission_type!=1} style="display:none;" {/if}>
    <div class='alert alert-danger'>
        填写佣金规则,如果是数字(只能是纯数字),则是以固定金额给佣金<br>
        例如 1  就是按照卖一件,给分销商1元<br>
        如果上百分号<br>
        例如 1% 则是以支付商品金额的百分比给佣金
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">统一设置</label>
        <div class="col-sm-10 col-xs-10">
            <select id="commission_level1" class="form-control" style="width:200px;display: inline-block">
                <option value="">选择等级</option>
                {loop $commission_level $level}
                {if $level['key'] == 'default'}
                <option value="{$level['key']}">{$level['levelname']}</option>
                {else}
                <option value="{$level['id']}">{$level['levelname']}</option>
                {/if}
                {/loop}
            </select>
            <select id="commission_level2" class="form-control" style="width:200px;display: inline-block">
                <option value="">选择佣金级别</option>
                {php for($i=0;$i<$_W['shopset']['commission']['level'];$i++):}
                <option value="{$i}">{php echo $i+1}级佣金</option>
                {php endfor;}
            </select>
            <input id="commission_level3" class="form-control" style="width:100px;display: inline-block" placeholder="佣金设置">
            <a class="btn btn-danger" onclick="commission_change_all()">设置</a>
        </div>
    </div>
    <div id='tbcommission' style="padding-left:15px;" >
        <div id="commission" style="padding:0;">{if $item['hasoption']==1}{$commission_html}{/if}</div>
        <div id="commission_default" style="padding:0;overflow-x: auto;"></div>
    </div>
</div>
</div>
    </div>
</div>




<script>
    $(function () {
        $("label[for='commission_type0']").click(function () {
            $("#commission_1").hide();
            $("#commission_0").show();
        });
        $("label[for='commission_type1']").click(function () {

            commission_change();
            $("#commission_0").hide();
            $("#commission_1").show();
        });
    });
	//By QQ:834633039
    function commission_change() {
        var html = '<table class="table table-bordered table-condensed" {if count($commission_level) >5} style="width: {php echo count($commission_level)* 605}px;" {/if} ><thead><tr class="active">{loop $commission_level $level}<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level["levelname"]}</div></div></th>{/loop}</tr></thead><tbody><tr>{loop $commission_level $level}{if $level["key"]=="default"}<td>{php for ($c_i = 0; $c_i < $_W["shopset"]["commission"]["level"]; $c_i++): }<input name="commission_level_{$level["key"]}_default[]" type="text" class="form-control commission_{$level["key"]} commission_{$level["key"]}_default" value="{php echo $commission[$level["key"]]["option0"][$c_i ];}" style="display:inline;width: {php echo (96 / $_W["shopset"]["commission"]["level"])}%;" placeholder="{php echo $c_i+1}级"> {php endfor;}</td>{else}<td>{php for ($c_i = 0; $c_i < $_W["shopset"]["commission"]["level"]; $c_i++): }<input name="commission_level_{$level["id"]}_default[]" type="text" class="form-control commission_level{$level["id"]} commission_{$level["key"]}_default" value="{php echo $commission["level".$level["id"]]["option0"][$c_i ];}" style="display:inline;width: {php echo (96 / $_W["shopset"]["commission"]["level"])}%;" placeholder="{php echo $c_i+1}级"> {php endfor;}</td>{/if}{/loop}</tr></tbody></table>';
        if ($("#commission").html()=='')
        {
            $("#commission_default").html(html);
            $("#commission_default").show();
        }
        else
        {
            $("#commission_default").html('');
            $("#commission_default").show();
        }
    }
    commission_change();

    function commission_change_all() {
        var commission_level1 = $("#commission_level1").val();
        var commission_level2 = $("#commission_level2").val();
        var commission_level3 = $("#commission_level3").val();

        if (commission_level1=='')
        {
            tip.msgbox.err('请选择分销商等级');
            return false;
        }
        if (commission_level2=='')
        {
            tip.msgbox.err('请选择佣金等级');
            return false;
        }
        if (commission_level3=='')
        {
            tip.msgbox.err('请填写佣金比例');
            return false;
        }

        if (commission_level1=='default')
        {
            $(".commission_default").each(function (key,val) {
                if(key%{$_W['shopset']['commission']['level']} == commission_level2)
                {
                    $(this).val(commission_level3);
                }
            });
        }
        else
        {
            $(".commission_level"+commission_level1).each(function (key,val) {
                if(key%{$_W['shopset']['commission']['level']} == commission_level2)
                {
                    $(this).val(commission_level3);
                }
            });
        }
    }
</script>
<!--OTEzNzAyMDIzNTAzMjQyOTE0-->